/*
 * Powered By dico
 * Since 2017 - 2018
 */
package com.seeyoui.kensite.bussiness.orderlang.product.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.seeyoui.kensite.bussiness.orderlang.order.domain.Order;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.Product;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.ProductCusIndexVO;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.ProductQueryDTO;
import com.seeyoui.kensite.bussiness.orderlang.product.domain.ProductVO;
import com.seeyoui.kensite.bussiness.orderlang.product.service.ProductService;
import com.seeyoui.kensite.bussiness.orderlang.productActivityDetail.service.ProductActivityDetailService;
import com.seeyoui.kensite.bussiness.orderlang.productAttachment.domain.ProductAttachment;
import com.seeyoui.kensite.bussiness.orderlang.productAttachment.service.ProductAttachmentService;
import com.seeyoui.kensite.bussiness.orderlang.productCategory.service.ProductCategoryService;
import com.seeyoui.kensite.bussiness.orderlang.productDetail.domain.ProductDetail;
import com.seeyoui.kensite.bussiness.orderlang.productDetail.service.ProductDetailService;
import com.seeyoui.kensite.bussiness.orderlang.productLabel.domain.ProductLabel;
import com.seeyoui.kensite.bussiness.orderlang.productLabel.service.ProductLabelService;
import com.seeyoui.kensite.bussiness.orderlang.productPrice.domain.ProductPrice;
import com.seeyoui.kensite.bussiness.orderlang.productPrice.domain.ProductPriceDTO;
import com.seeyoui.kensite.bussiness.orderlang.productPrice.service.ProductPriceService;
import com.seeyoui.kensite.bussiness.orderlang.productSpec.domain.ProductSpec;
import com.seeyoui.kensite.bussiness.orderlang.productSpec.service.ProductSpecService;
import com.seeyoui.kensite.bussiness.orderlang.productUnit.service.ProductUnitService;
import com.seeyoui.kensite.bussiness.orderlang.specification.domain.Specification;
import com.seeyoui.kensite.bussiness.orderlang.specification.service.SpecificationService;
import com.seeyoui.kensite.bussiness.orderlang.warehouseProduct.service.WarehouseProductService;
import com.seeyoui.kensite.common.base.controller.BaseController;
import com.seeyoui.kensite.common.base.domain.EasyUIDataGrid;
import com.seeyoui.kensite.common.base.domain.Page;
import com.seeyoui.kensite.common.constants.StringConstant;
import com.seeyoui.kensite.common.util.DateUtils;
import com.seeyoui.kensite.common.util.RequestResponseUtil;
import com.seeyoui.kensite.common.util.Result;
import com.seeyoui.kensite.common.util.StringUtils;
import com.seeyoui.kensite.common.util.excel.ExportExcel;
import com.sun.star.installation.protocols;
/**
 * Product
 * @author dico
 * @version 2.0
 * @since 1.0
 * @date 2018-02-07
 */

@Controller
@RequestMapping(value = "product/product")
public class ProductController extends BaseController {
	
	@Autowired
	private ProductService productService;
	@Autowired
	private ProductAttachmentService productAttachmentService;
	@Autowired
	private ProductLabelService productLabelService;
	@Autowired
	private ProductDetailService productDetailService;
	@Autowired
	private ProductPriceService productPriceService;
	@Autowired
	private ProductSpecService productSpecService;
	@Autowired
	private WarehouseProductService wareHouseProductService;
	@Autowired
	private SpecificationService specificationService;
	@Autowired
	private ProductUnitService productUnitService;
	@Autowired
	private ProductActivityDetailService productActivityDetailService;
	@Autowired
	private ProductCategoryService productCategoryService;
	
	/**
	 * 展示列表页面
	 * @param modelMap
	 * @param module
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:view")
	@RequestMapping(value = "/{page}")
	public ModelAndView view(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, @PathVariable String page) throws Exception {
		return new ModelAndView("bussiness/orderlang/product/"+page, modelMap);
	}
	
	/**
	 * 跳转新增商品页面
	 * @return
	 */
	@RequestMapping("/goProductAdd")
	public String goProductAdd(Model model){
		model.addAttribute("actionType", "新增商品");
		return "/bussiness/orderlang/distributor/add_product";
	}
	
	@RequestMapping("/goProductListPage")
	public String goProductListPage(){
		return "/bussiness/orderlang/customer/product_list";
	}
	
	@RequestMapping("/goProductDetail")
	public String goProductDetail(){
		return "/bussiness/orderlang/customer/product_detail";
	}
	
	/**
	 * 跳转商品修改页面
	 * @param model
	 * @param productId
	 * @return
	 */
	@RequestMapping("/goProductUpdate")
	public String goProductUpdate(Model model,String productId){
		ProductVO product = productService.findProductById(productId);
		String littleUnitName = productUnitService.findOne(product.getLittleUnitId()).getUnitName();
		if(StringUtils.isNotBlank(product.getBigUnitId())){
			String bigUnitName = productUnitService.findOne(product.getBigUnitId()).getUnitName();
			model.addAttribute("bigUnitName", bigUnitName);
		}
		model.addAttribute("littleUnitName", littleUnitName);
		model.addAttribute("product", product);
		model.addAttribute("actionType", "修改商品");
		return "/bussiness/orderlang/distributor/add_product";
	}
	
	/**
	 * 跳转导入商品页面
	 * @return
	 */
	@RequestMapping("/goProductImport")
	public String goProductImport(){
		return "/bussiness/orderlang/distributor/product_import";
	}
	
	/**
	 * 根据条件查询商品列表(经销商端商品管理)
	 * @param productName
	 * @param isRelease
	 * @param quantity
	 * @param categoryName
	 * @param label
	 * @param product
	 * @param marketPrice
	 * @param createDate
	 * @param updateDate
	 * @param productQueryDTO
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping(value = "/productList", method=RequestMethod.POST)
	@ResponseBody
	public Result findListByCondition(String productName, String isRelease,
			Product product,
			ProductQueryDTO productQueryDTO, int page, int rows) throws Exception {
		List<ProductVO> productList = productService.findListByCondition(productName, isRelease, 
				productQueryDTO, page, rows);
		int total = productService.findTotal(product);
		Page<Order> pageInfo = new Page<Order>(page, rows, total);
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("rows", productList);
        dataMap.put("page", pageInfo);
        if (productList.isEmpty()) {
			return Result.failure("查询失败");
		} else {
			return Result.success(dataMap);
		}
	}
	
	/**
	 * 首页商品及轮播图查询
	 * @return
	 */
	@RequestMapping(value = "/indexProductList", method=RequestMethod.POST)
	@ResponseBody
	public Result findIndexProductList(){
		List<ProductCusIndexVO> productList =  productActivityDetailService.findIndexProductList();
		for (ProductCusIndexVO productCusIndexVO : productList) {
			productCusIndexVO.setMaxPrice(productPriceService.findMaxPriceByProductId(productCusIndexVO.getProductId()));
			productCusIndexVO.setMinPrice(productPriceService.findMinPriceByProductId(productCusIndexVO.getProductId()));
		}
		if(productList.size() > 0){
			return Result.success(productList);
		}else{
			return Result.failure("查询失败");
		}
	}
	
	/**
	 * 根据分类id查找商品列表（分页）
	 * @param categoryId
	 * @return
	 */
	@RequestMapping(value = "/productListByCategoryId", method=RequestMethod.POST)
	@ResponseBody
	public Result findProductListByCategoryId(String categoryId){
		String level = productCategoryService.getCategoryLevelById(categoryId);
		List<ProductCusIndexVO> productList = new ArrayList<ProductCusIndexVO>();
		if("1".equals(level)){
			productList = productService.findProductListFirstLevel(categoryId);
		}else if("2".equals(level)){
			productList = productService.findProductListSecondLevel(categoryId);
		}else if("3".equals(level)){
			productList = productService.findProductListThirdLevel(categoryId);
		}
		if(productList.size() > 0){
			for (ProductCusIndexVO productCusIndexVO : productList) {
				productCusIndexVO.setMaxPrice(productPriceService.findMaxPriceByProductId(productCusIndexVO.getProductId()));
				productCusIndexVO.setMinPrice(productPriceService.findMinPriceByProductId(productCusIndexVO.getProductId()));
			}
			return Result.success(productList);
		}else{
			return Result.failure("查询失败");
		}
	}
	
	@RequestMapping(value = "/productByProductId", method=RequestMethod.POST)
	@ResponseBody
	public Result findProductByProductId(String productId){
		ProductVO product = productService.findProductDetailById(productId);
		if(product != null){
			return Result.success(product);
		}else{
			return Result.failure("查询失败");
		}
	}
	
	/**
	 * 新增商品方法
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/productSave", method=RequestMethod.POST)
	@ResponseBody
	public Result productSave(HttpServletRequest request,Product product,String partnerDiscount,
			String diamondMemberDiscount,String goldMemberDiscount,String normal){
		
		String productList = request.getParameter("productList");
		List<ProductPriceDTO> priceList = JSONArray.parseArray(productList, ProductPriceDTO.class);
		List<String> compareList = new ArrayList<String>();
		for (ProductPriceDTO productPriceDTO : priceList) {
			List<Specification> compareSpecList =  productPriceDTO.getSpecList();
			String tempSpecValue = "";
			for (Specification specification : compareSpecList) {
				tempSpecValue += specification.getSpecValue();
			}
			compareList.add(tempSpecValue);
		}
		for(int i=0;i<compareList.size();i++){
			for(int j=i+1;j<compareList.size();j++){
				if(compareList.get(i).equals(compareList.get(j))){
					return Result.failure("商品规格重复，请修改");
				}
			}
		}
		
		
		product.setDistributorId("d37e46fc92294833a68547808f61d074");
		productService.save(product);
		// 图片
		String[] hrefs = request.getParameterValues("imgHref");
		int seq = 0;
		if(hrefs != null){
			for (String href : hrefs) {
				ProductAttachment productAttachment = new ProductAttachment();
				productAttachment.setProductId(product.getId());
				productAttachment.setUrl(href);
				productAttachment.setType("0");
				productAttachment.setSeq(String.valueOf(seq++));
				productAttachmentService.save(productAttachment);
			}
		}
		String fileHref = request.getParameter("attachment-upload");
		if(StringUtils.isNotBlank(fileHref)){
			ProductAttachment productAttachment = new ProductAttachment();
			productAttachment.setProductId(product.getId());
			productAttachment.setUrl(fileHref);
			productAttachment.setType("1");
			productAttachment.setSeq(String.valueOf(seq));
			productAttachmentService.save(productAttachment);
		}
		
		// 标签
		String productLabels = request.getParameter("productTag");
		String[] labels = productLabels.split(",");
		for (String label : labels) {
			ProductLabel productLabel = new ProductLabel();
			productLabel.setProductId(product.getId());
			productLabel.setLabel(label);
			productLabelService.save(productLabel);
		}
		// 详情
		String detailInfo = request.getParameter("content");
		ProductDetail productDetail = new ProductDetail();
		productDetail.setProductId(product.getId());
		productDetail.setDetail(detailInfo);
		productDetailService.save(productDetail);
		
		// 规格定义
		String specList = request.getParameter("specList");
		List<Specification> tempSpecList = new ArrayList<Specification>();
		List<Specification> specli = JSONArray.parseArray(specList, Specification.class);
		for (Specification specification : specli) {
			specificationService.save(specification);
			tempSpecList.add(specification);
		}
		// 价格、规格
		/*String productList = request.getParameter("productList");
		List<ProductPriceDTO> priceList = JSONArray.parseArray(productList, ProductPriceDTO.class);*/
		for (ProductPriceDTO productPriceDTO : priceList) {
			ProductPrice productPrice = new ProductPrice();
			productPrice.setDiamondDiscount(diamondMemberDiscount);
			productPrice.setDiamondPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(diamondMemberDiscount))/100));
			productPrice.setGoldDiscount(goldMemberDiscount);
			productPrice.setGoldPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(goldMemberDiscount))/100));
			productPrice.setGeneralDiscount(normal);
			productPrice.setGeneralPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(normal))/100));
			productPrice.setShareholderDiscount(partnerDiscount);
			productPrice.setShareholderPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(partnerDiscount))/100));
			productPrice.setCostPrice(productPriceDTO.getCostPrice());
			productPrice.setMarketPrice(productPriceDTO.getMarketPrice());
			productPrice.setMoq(productPriceDTO.getMoq());
			productPrice.setProductId(product.getId());
			productPriceService.save(productPrice);
			
			List<Specification> specProductList = productPriceDTO.getSpecList();
			for (Specification specification : specProductList) {
				ProductSpec productSpec = new ProductSpec();
				productSpec.setProductPriceId(productPrice.getId());
				productSpec.setSpecName(specification.getSpecName());
				productSpec.setSpecValue(specification.getSpecValue());
				for (Specification temp : tempSpecList) {
					if(!"".equals(temp.getSpecName()) && !"".equals(specification.getSpecName())){
						if(temp.getSpecName().equals(specification.getSpecName())){
							productSpec.setSpecId(temp.getId());
						}
					}
				}
				productSpecService.save(productSpec);
			}
		}
		
		return Result.success("新增成功");
	}
	
	/**
	 * 商品修改方法
	 * @param request
	 * @param product
	 * @param partnerDiscount
	 * @param diamondMemberDiscount
	 * @param goldMemberDiscount
	 * @param normal
	 * @return
	 */
	@RequestMapping(value = "/productUpdate", method=RequestMethod.POST)
	@ResponseBody
	public Result productUpdate(HttpServletRequest request,Product product,String partnerDiscount,String diamondMemberDiscount,String goldMemberDiscount,String normal){
		
		String productList = request.getParameter("productList");
		List<ProductPriceDTO> priceList = JSONArray.parseArray(productList, ProductPriceDTO.class);
		List<String> compareList = new ArrayList<String>();
		for (ProductPriceDTO productPriceDTO : priceList) {
			List<Specification> compareSpecList =  productPriceDTO.getSpecList();
			String tempSpecValue = "";
			for (Specification specification : compareSpecList) {
				tempSpecValue += specification.getSpecValue();
			}
			compareList.add(tempSpecValue);
		}
		for(int i=0;i<compareList.size();i++){
			for(int j=i+1;j<compareList.size();j++){
				if(compareList.get(i).equals(compareList.get(j))){
					return Result.failure("商品规格重复，请修改");
				}
			}
		}
		
		productService.update(product);
		
		// 图片
		String[] hrefs = request.getParameterValues("imgHref");
		int seq = 0;
		if(hrefs != null){
			productAttachmentService.deleteByProductId(product.getId());
			for (String href : hrefs) {
				ProductAttachment productAttachment = new ProductAttachment();
				productAttachment.setProductId(product.getId());
				productAttachment.setUrl(href);
				productAttachment.setType("0");
				productAttachment.setSeq(String.valueOf(seq++));
				productAttachmentService.save(productAttachment);
			}
		}
		String fileHref = request.getParameter("attachment-upload");
		if(StringUtils.isNotBlank(fileHref)){
			productAttachmentService.deleteFileByProductId(product.getId());
			ProductAttachment productAttachment = new ProductAttachment();
			productAttachment.setProductId(product.getId());
			productAttachment.setUrl(fileHref);
			productAttachment.setType("1");
			productAttachment.setSeq(String.valueOf(seq));
			productAttachmentService.save(productAttachment);
		}
		
		// 详情
		String detailInfo = request.getParameter("content");
		if(StringUtils.isNotBlank(detailInfo)){
			productDetailService.deleteByProductId(product.getId());
			ProductDetail productDetail = new ProductDetail();
			productDetail.setProductId(product.getId());
			productDetail.setDetail(detailInfo);
			productDetailService.save(productDetail);
		}
		
		// 标签
		productLabelService.deleteByProductId(product.getId());
		String productLabels = request.getParameter("productTag");
		String[] labels = productLabels.split(",");
		for (String label : labels) {
			ProductLabel productLabel = new ProductLabel();
			productLabel.setProductId(product.getId());
			productLabel.setLabel(label);
			productLabelService.save(productLabel);
		}
		
		
		// 规格定义
		String specList = request.getParameter("specList");
		List<Specification> tempSpecList = new ArrayList<Specification>();
		if(StringUtils.isNotEmpty(specList)){
			String productPriceId = productPriceService.findOneByProductId(product.getId()).getId();
			List<ProductSpec> ppList = productSpecService.findListByProductPriceId(productPriceId);
			List<String> specIdList = new ArrayList<String>();
			for (ProductSpec productSpec : ppList) {
				specIdList.add(productSpec.getSpecId());
			}
			specificationService.delete(specIdList);
			
			List<Specification> specli = JSONArray.parseArray(specList, Specification.class);
			for (Specification specification : specli) {
				specificationService.save(specification);
				tempSpecList.add(specification);
			}
		}
		
		// 价格、规格
		/*String productList = request.getParameter("productList");*/
		if(StringUtils.isNotEmpty(productList)){
			List<ProductPrice> idList = productPriceService.findIdsByProductId(product.getId());
			List<String> priceId = new ArrayList<String>();
			for (ProductPrice string : idList) {
				priceId.add(string.getId());
			}
			productSpecService.deleteByPriceId(priceId);
			productPriceService.deleteByProductId(product.getId());
			
			/*List<ProductPriceDTO> priceList = JSONArray.parseArray(productList, ProductPriceDTO.class);*/
			for (ProductPriceDTO productPriceDTO : priceList) {
				ProductPrice productPrice = new ProductPrice();
				productPrice.setDiamondDiscount(diamondMemberDiscount);
				productPrice.setDiamondPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(diamondMemberDiscount))/100));
				productPrice.setGoldDiscount(goldMemberDiscount);
				productPrice.setGoldPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(goldMemberDiscount))/100));
				productPrice.setGeneralDiscount(normal);
				productPrice.setGeneralPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(normal))/100));
				productPrice.setShareholderDiscount(partnerDiscount);
				productPrice.setShareholderPrice(String.valueOf(productPriceDTO.getCostPrice() * (Integer.parseInt(partnerDiscount))/100));
				productPrice.setCostPrice(productPriceDTO.getCostPrice());
				productPrice.setMarketPrice(productPriceDTO.getMarketPrice());
				productPrice.setMoq(productPriceDTO.getMoq());
				productPrice.setProductId(product.getId());
				productPriceService.save(productPrice);
				
				List<Specification> specProductList = productPriceDTO.getSpecList();
				for (Specification specification : specProductList) {
					ProductSpec productSpec = new ProductSpec();
					productSpec.setProductPriceId(productPrice.getId());
					productSpec.setSpecName(specification.getSpecName());
					productSpec.setSpecValue(specification.getSpecValue());
					for (Specification temp : tempSpecList) {
						if(!"".equals(temp.getSpecName()) && !"".equals(specification.getSpecName())){
							if(temp.getSpecName().equals(specification.getSpecName())){
								productSpec.setSpecId(temp.getId());
							}
						}
					}
					productSpecService.save(productSpec);
				}
			}
		}
		
		return Result.success("修改成功");
		
	}
	
	/**
	 * 商品发布
	 * @param ids
	 * @param product
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/releaseProduct", method=RequestMethod.POST)
	@ResponseBody
	public Result releaseProduct(String id,Product product) throws Exception {
		String[] productIds = id.split(",");
		for (String ids : productIds) {
			product.setId(ids);
			product.setIsRelease("1");
			productService.update(product);
		}
		return Result.success("成功");
	}
	
	/**
     * 出入库查询商品列表
     * @param modelMap
     * @param product
     * @return
     * @throws Exception
     */
    //@RequiresPermissions("product:product:select")
    @RequestMapping(value = "/findProductByKey", method=RequestMethod.POST)
    @ResponseBody
    public Object findProductByKey(HttpSession session,
            HttpServletResponse response, HttpServletRequest request,
            ModelMap modelMap, Product product, String key) throws Exception {
        Map map = new HashMap();
        map.put("key", key);
        List<Product> productList = productService.findProductsByKey(map);
        for (Product queryProduct : productList) {
            String specValue = "";
            String specId = "";
            ProductSpec queryProductSpec = new ProductSpec();
            queryProductSpec.setProductPriceId(queryProduct.getCategoryId());
            queryProductSpec.setDelFlag("0");
            List<ProductSpec> productSpecList = productSpecService.findList(queryProductSpec);
            for (ProductSpec productSpec : productSpecList) {
                specId += ","+productSpec.getId();
                specValue += ","+productSpec.getSpecValue();
            }
            queryProduct.setKeyWord(specValue.substring(1));
            queryProduct.setBrandId(specId.substring(1));
        }
        EasyUIDataGrid eudg = new EasyUIDataGrid();
        eudg.setRows(productList);
//      int total = productService.findTotal(product);
//      eudg.setTotal(String.valueOf(total));
        return eudg;
    }
	
	/**
	 * 根据ID查询单条数据
	 * @param modelMap
	 * @param module
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:select")
	@RequestMapping(value = "/data/{id}")
	@ResponseBody
	public Object data(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, @PathVariable String id) throws Exception {
		Product product = productService.findOne(id);
		return product;
	}
	
	/**
     * 获取列表展示数据
     * @param modelMap
     * @param warehouse
     * @return
     * @throws Exception
     */
    //@RequiresPermissions("warehouse:warehouse:select")
    @RequestMapping(value = "/index", method=RequestMethod.POST)
    @ResponseBody
    public Object index(HttpSession session,
            HttpServletResponse response, HttpServletRequest request,
            ModelMap modelMap, Product product,int page,int rows) throws Exception {
        product.setPage(page);
        product.setRows(rows);
        List<Product> productList = productService.findList(product);
        int total = productService.findTotal(product);
        Page<Product> pageInfo = new Page<Product>(page, rows, total);
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("rows", productList);
        dataMap.put("page", pageInfo);
        return dataMap;
    }
	
	/**
	 * 根据ID查询单条数据并返回相应表单
	 * @param modelMap
	 * @param module
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:view")
	@RequestMapping(value = "/form/{page}/{id}")
	public ModelAndView form(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, @PathVariable String page, @PathVariable String id) throws Exception {
		Product product = productService.findOne(id);
		modelMap.put("product", product);
		return new ModelAndView("bussiness/orderlang/product/"+page, modelMap);
	}
	
	/**
	 * 获取列表展示数据
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:select")
	@RequestMapping(value = "/list/data", method=RequestMethod.POST)
	@ResponseBody
	public Object listData(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		List<Product> productList = productService.findList(product);
		int total = productService.findTotal(product);
		EasyUIDataGrid eudg = new EasyUIDataGrid();
		eudg.setTotal(String.valueOf(total));
		eudg.setRows(productList);
		return eudg;
	}
	
	/**
	 * 获取列表展示数据带分页器用于jsp自己做分页
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:view")
	@RequestMapping(value = "/list/page", method=RequestMethod.POST)
	@ResponseBody
	public Object listPage(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		List<Product> productList = productService.findList(product);
		int total = productService.findTotal(product);
		Page<Product> page = new Page<Product>(product.getPage(), product.getRows(), total);
		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("rows", productList);
		dataMap.put("page", page);
		return dataMap;
	}
	
	/**
	 * 获取所有数据
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:select")
	@RequestMapping(value = "/list/all", method=RequestMethod.POST)
	@ResponseBody
	public Object listAll(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		List<Product> productList = productService.findAll(product);
		return productList;
	}
	
	/**
	 * 保存新增的数据
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:insert")
	@RequestMapping(value = "/save", method=RequestMethod.POST)
	@ResponseBody
	public String save(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		if (!beanValidator(modelMap, product)){
			RequestResponseUtil.putResponseStr(session, response, request, modelMap, StringConstant.FALSE);
			return null;
		}
		productService.save(product);
		RequestResponseUtil.putResponseStr(session, response, request, modelMap, StringConstant.TRUE);
		return null;
	}
	
	/**
	 * 保存修改的数据
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:update")
	@RequestMapping(value = "/update", method=RequestMethod.POST)
	@ResponseBody
	public String update(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		if (!beanValidator(modelMap, product)){
			RequestResponseUtil.putResponseStr(session, response, request, modelMap, StringConstant.FALSE);
			return null;
		}
		productService.update(product);
		RequestResponseUtil.putResponseStr(session, response, request, modelMap, StringConstant.TRUE);
		return null;
	}
	
	/**
	 * 删除数据库
	 * @param modelMap
	 * @param productId
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:delete")
	@RequestMapping(value = "/delete", method=RequestMethod.POST)
	@ResponseBody
	public Result delete(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, String id) throws Exception {
		List<String> listId = Arrays.asList(id.split(","));
		productService.delete(listId);
		//RequestResponseUtil.putResponseStr(session, response, request, modelMap, StringConstant.TRUE);
		return Result.success("删除");
	}
	
	/**
	 * 假删除
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:delete")
	@RequestMapping(value = "/remove", method=RequestMethod.POST)
	@ResponseBody
	public String remove(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		productService.remove(product);
		RequestResponseUtil.putResponseStr(session, response, request, modelMap, StringConstant.TRUE);
		return null;
	}

	/**
	 * 导出Excel数据
	 * @param modelMap
	 * @param product
	 * @return
	 * @throws Exception
	 */
	//@RequiresPermissions("product:product:export")
	@RequestMapping(value = "/export")
	public String export(HttpSession session,
			HttpServletResponse response, HttpServletRequest request,
			ModelMap modelMap, Product product) throws Exception {
		String fileName = DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
		List<Product> productList = productService.findAll(product);
		new ExportExcel(null, Product.class).setDataList(productList).write(response, fileName).dispose();
		return null;
	}
}
